


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > LevelFactory</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.level</a>
</div>

<h1>Coverage Summary for Class: LevelFactory (nl.tudelft.jpacman.level)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LevelFactory</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/4)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/17)
  </span>
</td>
</tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455$auxiliary$7fdpIJji</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455$auxiliary$f66oz0wP</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455$auxiliary$hcfepc6F</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455$auxiliary$ZJZyByRA</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$MockitoMock$1152458455$auxiliary$zQGbhMZg</td>
  </tr>
  <tr>
    <td class="name">LevelFactory$RandomGhost</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/2)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/6)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/20)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.level;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import java.util.List;
<i class="no-highlight">4</i>&nbsp;import java.util.Map;
<i class="no-highlight">5</i>&nbsp;import java.util.Optional;
<i class="no-highlight">6</i>&nbsp;
<i class="no-highlight">7</i>&nbsp;import nl.tudelft.jpacman.board.Board;
<i class="no-highlight">8</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
<i class="no-highlight">9</i>&nbsp;import nl.tudelft.jpacman.board.Square;
<i class="no-highlight">10</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
<i class="no-highlight">11</i>&nbsp;import nl.tudelft.jpacman.npc.ghost.GhostColor;
<i class="no-highlight">12</i>&nbsp;import nl.tudelft.jpacman.npc.ghost.GhostFactory;
<i class="no-highlight">13</i>&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
<i class="no-highlight">14</i>&nbsp;import nl.tudelft.jpacman.sprite.PacManSprites;
<i class="no-highlight">15</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
<i class="no-highlight">16</i>&nbsp;
<i class="no-highlight">17</i>&nbsp;/**
<i class="no-highlight">18</i>&nbsp; * Factory that creates levels and units.
<i class="no-highlight">19</i>&nbsp; *
<i class="no-highlight">20</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">21</i>&nbsp; */
<i class="no-highlight">22</i>&nbsp;public class LevelFactory {
<i class="no-highlight">23</i>&nbsp;
<i class="no-highlight">24</i>&nbsp;    private static final int GHOSTS = 4;
<i class="no-highlight">25</i>&nbsp;    private static final int BLINKY = 0;
<i class="no-highlight">26</i>&nbsp;    private static final int INKY = 1;
<i class="no-highlight">27</i>&nbsp;    private static final int PINKY = 2;
<i class="no-highlight">28</i>&nbsp;    private static final int CLYDE = 3;
<i class="no-highlight">29</i>&nbsp;
<i class="no-highlight">30</i>&nbsp;    /**
<i class="no-highlight">31</i>&nbsp;     * The default value of a pellet.
<i class="no-highlight">32</i>&nbsp;     */
<i class="no-highlight">33</i>&nbsp;    private static final int PELLET_VALUE = 10;
<i class="no-highlight">34</i>&nbsp;
<i class="no-highlight">35</i>&nbsp;    /**
<i class="no-highlight">36</i>&nbsp;     * The sprite store that provides sprites for units.
<i class="no-highlight">37</i>&nbsp;     */
<i class="no-highlight">38</i>&nbsp;    private final PacManSprites sprites;
<i class="no-highlight">39</i>&nbsp;
<i class="no-highlight">40</i>&nbsp;    /**
<i class="no-highlight">41</i>&nbsp;     * Used to cycle through the various ghost types.
<i class="no-highlight">42</i>&nbsp;     */
<i class="no-highlight">43</i>&nbsp;    private int ghostIndex;
<i class="no-highlight">44</i>&nbsp;
<i class="no-highlight">45</i>&nbsp;    /**
<i class="no-highlight">46</i>&nbsp;     * The factory providing ghosts.
<i class="no-highlight">47</i>&nbsp;     */
<i class="no-highlight">48</i>&nbsp;    private final GhostFactory ghostFact;
<i class="no-highlight">49</i>&nbsp;
<i class="no-highlight">50</i>&nbsp;    /**
<i class="no-highlight">51</i>&nbsp;     * The way to calculate points upon collisions.
<i class="no-highlight">52</i>&nbsp;     */
<i class="no-highlight">53</i>&nbsp;    private final PointCalculator pointCalculator;
<i class="no-highlight">54</i>&nbsp;
<i class="no-highlight">55</i>&nbsp;    /**
<i class="no-highlight">56</i>&nbsp;     * Creates a new level factory.
<i class="no-highlight">57</i>&nbsp;     *
<i class="no-highlight">58</i>&nbsp;     * @param spriteStore
<i class="no-highlight">59</i>&nbsp;     *            The sprite store providing the sprites for units.
<i class="no-highlight">60</i>&nbsp;     * @param ghostFactory
<i class="no-highlight">61</i>&nbsp;     *            The factory providing ghosts.
<i class="no-highlight">62</i>&nbsp;     * @param pointCalculator
<i class="no-highlight">63</i>&nbsp;     *            The algorithm to calculate the points.
<i class="no-highlight">64</i>&nbsp;     */
<i class="no-highlight">65</i>&nbsp;    public LevelFactory(PacManSprites spriteStore,
<i class="no-highlight">66</i>&nbsp;                        GhostFactory ghostFactory,
<b class="nc"><i class="no-highlight">67</i>&nbsp;                        PointCalculator pointCalculator) {</b>
<b class="nc"><i class="no-highlight">68</i>&nbsp;        this.sprites = spriteStore;</b>
<b class="nc"><i class="no-highlight">69</i>&nbsp;        this.ghostIndex = -1;</b>
<b class="nc"><i class="no-highlight">70</i>&nbsp;        this.ghostFact = ghostFactory;</b>
<b class="nc"><i class="no-highlight">71</i>&nbsp;        this.pointCalculator = pointCalculator;</b>
<b class="nc"><i class="no-highlight">72</i>&nbsp;    }</b>
<i class="no-highlight">73</i>&nbsp;
<i class="no-highlight">74</i>&nbsp;    /**
<i class="no-highlight">75</i>&nbsp;     * Creates a new level from the provided data.
<i class="no-highlight">76</i>&nbsp;     *
<i class="no-highlight">77</i>&nbsp;     * @param board
<i class="no-highlight">78</i>&nbsp;     *            The board with all ghosts and pellets occupying their squares.
<i class="no-highlight">79</i>&nbsp;     * @param ghosts
<i class="no-highlight">80</i>&nbsp;     *            A list of all ghosts on the board.
<i class="no-highlight">81</i>&nbsp;     * @param startPositions
<i class="no-highlight">82</i>&nbsp;     *            A list of squares from which players may start the game.
<i class="no-highlight">83</i>&nbsp;     * @return A new level for the board.
<i class="no-highlight">84</i>&nbsp;     */
<i class="no-highlight">85</i>&nbsp;    public Level createLevel(Board board, List&lt;Ghost&gt; ghosts, List&lt;Square&gt; startPositions) {
<i class="no-highlight">86</i>&nbsp;
<i class="no-highlight">87</i>&nbsp;        // We&#39;ll adopt the simple collision map for now.
<b class="nc"><i class="no-highlight">88</i>&nbsp;        CollisionMap collisionMap = new PlayerCollisions(pointCalculator);</b>
<i class="no-highlight">89</i>&nbsp;
<b class="nc"><i class="no-highlight">90</i>&nbsp;        return new Level(board, ghosts, startPositions, collisionMap);</b>
<i class="no-highlight">91</i>&nbsp;    }
<i class="no-highlight">92</i>&nbsp;
<i class="no-highlight">93</i>&nbsp;    /**
<i class="no-highlight">94</i>&nbsp;     * Creates a new ghost.
<i class="no-highlight">95</i>&nbsp;     *
<i class="no-highlight">96</i>&nbsp;     * @return The new ghost.
<i class="no-highlight">97</i>&nbsp;     */
<i class="no-highlight">98</i>&nbsp;    Ghost createGhost() {
<b class="nc"><i class="no-highlight">99</i>&nbsp;        ghostIndex++;</b>
<b class="nc"><i class="no-highlight">100</i>&nbsp;        ghostIndex %= GHOSTS;</b>
<b class="nc"><i class="no-highlight">101</i>&nbsp;        switch (ghostIndex) {</b>
<i class="no-highlight">102</i>&nbsp;            case BLINKY:
<b class="nc"><i class="no-highlight">103</i>&nbsp;                return ghostFact.createBlinky();</b>
<i class="no-highlight">104</i>&nbsp;            case INKY:
<b class="nc"><i class="no-highlight">105</i>&nbsp;                return ghostFact.createInky();</b>
<i class="no-highlight">106</i>&nbsp;            case PINKY:
<b class="nc"><i class="no-highlight">107</i>&nbsp;                return ghostFact.createPinky();</b>
<i class="no-highlight">108</i>&nbsp;            case CLYDE:
<b class="nc"><i class="no-highlight">109</i>&nbsp;                return ghostFact.createClyde();</b>
<i class="no-highlight">110</i>&nbsp;            default:
<b class="nc"><i class="no-highlight">111</i>&nbsp;                return new RandomGhost(sprites.getGhostSprite(GhostColor.RED));</b>
<i class="no-highlight">112</i>&nbsp;        }
<i class="no-highlight">113</i>&nbsp;    }
<i class="no-highlight">114</i>&nbsp;
<i class="no-highlight">115</i>&nbsp;    /**
<i class="no-highlight">116</i>&nbsp;     * Creates a new pellet.
<i class="no-highlight">117</i>&nbsp;     *
<i class="no-highlight">118</i>&nbsp;     * @return The new pellet.
<i class="no-highlight">119</i>&nbsp;     */
<i class="no-highlight">120</i>&nbsp;    public Pellet createPellet() {
<b class="nc"><i class="no-highlight">121</i>&nbsp;        return new Pellet(PELLET_VALUE, sprites.getPelletSprite());</b>
<i class="no-highlight">122</i>&nbsp;    }
<i class="no-highlight">123</i>&nbsp;
<i class="no-highlight">124</i>&nbsp;    /**
<i class="no-highlight">125</i>&nbsp;     * Implementation of an NPC that wanders around randomly.
<i class="no-highlight">126</i>&nbsp;     *
<i class="no-highlight">127</i>&nbsp;     * @author Jeroen Roosen
<i class="no-highlight">128</i>&nbsp;     */
<i class="no-highlight">129</i>&nbsp;    private static final class RandomGhost extends Ghost {
<i class="no-highlight">130</i>&nbsp;
<i class="no-highlight">131</i>&nbsp;        /**
<i class="no-highlight">132</i>&nbsp;         * The suggested delay between moves.
<i class="no-highlight">133</i>&nbsp;         */
<i class="no-highlight">134</i>&nbsp;        private static final long DELAY = 175L;
<i class="no-highlight">135</i>&nbsp;
<i class="no-highlight">136</i>&nbsp;        /**
<i class="no-highlight">137</i>&nbsp;         * Creates a new random ghost.
<i class="no-highlight">138</i>&nbsp;         *
<i class="no-highlight">139</i>&nbsp;         * @param ghostSprite
<i class="no-highlight">140</i>&nbsp;         *            The sprite for the ghost.
<i class="no-highlight">141</i>&nbsp;         */
<i class="no-highlight">142</i>&nbsp;        RandomGhost(Map&lt;Direction, Sprite&gt; ghostSprite) {
<b class="nc"><i class="no-highlight">143</i>&nbsp;            super(ghostSprite, (int) DELAY, 0);</b>
<b class="nc"><i class="no-highlight">144</i>&nbsp;        }</b>
<i class="no-highlight">145</i>&nbsp;
<i class="no-highlight">146</i>&nbsp;        @Override
<i class="no-highlight">147</i>&nbsp;        public Optional&lt;Direction&gt; nextAiMove() {
<b class="nc"><i class="no-highlight">148</i>&nbsp;            return Optional.empty();</b>
<i class="no-highlight">149</i>&nbsp;        }
<i class="no-highlight">150</i>&nbsp;    }
<i class="no-highlight">151</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
